<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

/**
 * 微信卡券投放二维码表单验证器
 * @package App\Http\Requests
 */
class AdminWxCardQrcodePost extends AdminBaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'type' => 'required|in:QR_CARD,QR_MULTIPLE_CARD',
            'title' => 'required',
            'card_info.card_id' => 'required_if:type,QR_CARD',
            'card_list.*.card_id' => 'required_if:type,QR_MULTIPLE_CARD',
        ];
    }

    /**
     * 定义错误信息
     * @return array
     */
    public function messages()
    {
        return [
            'type.required' => '请选择正确二维码类别',
            'type.in' => '请选择正确二维码类别',
            'card_info.card_id.required_if' => '卡券ID不能为空',
            'card_list.*.card_id.required_if' => '务必确保所有卡券ID不能为空',
        ];
    }
}
